package cn.itsource.pet.service.impl;

import cn.itsource.basic.service.BaseServiceImpl;
import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.GetRedisLoginVoUtil;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.mapper.SearchMasterMessageMapper;
import cn.itsource.pet.pojo.domain.SearchMasterMessage;
import cn.itsource.pet.pojo.dto.AuditDto;
import cn.itsource.pet.query.SearchMasterMessageQuery;
import cn.itsource.pet.service.SearchMasterMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchMasterMessageServiceImpl extends BaseServiceImpl<SearchMasterMessage, SearchMasterMessageQuery> implements SearchMasterMessageService {
    @Autowired
    SearchMasterMessageMapper messageMapper;

    @Override
    //publish 发布
    public AjaxResult publish(SearchMasterMessage message) {
        //设置userId
        Long userId = GetRedisLoginVoUtil.getUserId();
        message.setUserId(userId);
        //入库
        messageMapper.insertSelective(message);

        return AjaxResult.createSuccess();
    }

    @Override
    public PageList<SearchMasterMessage> findPageList(SearchMasterMessageQuery query) {
        //1.分页插件的使用
        PageHelper.startPage(query.getPage(), query.getSize());
        //2.执行分页语句 1，2顺序不能反  ，中间不能写代码
        List<SearchMasterMessage> pageList = messageMapper.findPageList(query);
        //3.封装到pageInfo里面去
        PageInfo<SearchMasterMessage> searchMasterMessagePageInfo = new PageInfo<>(pageList);
        //4.封装自定义pageList对象
        PageList<SearchMasterMessage> searchMasterMessagePageList = new PageList<>(searchMasterMessagePageInfo.getTotal(), searchMasterMessagePageInfo.getList());
        return searchMasterMessagePageList;
    }
//审核
    @Override
    public AjaxResult audit(AuditDto auditDto) {
//        修改审核状态
        messageMapper.audit(auditDto);

     return AjaxResult.createSuccess();
    }


}
